<?php

/**
 * This is the model class for table "gn_sales".
 *
 * The followings are the available columns in table 'gn_sales':
 * @property double $sale_id
 * @property integer $member_id
 * @property integer $product_id
 * @property integer $quantity
 * @property float $amount
 * @property string $dt_sale
 * @property string $dt_created
 */
class Sales extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Sales the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
		//return parent::model($className)->with('Members', 'Products')->findAll();
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'gn_sales';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('member_id, product_id, quantity, amount, dt_sale', 'required'),
			array('member_id, product_id, quantity', 'numerical', 'integerOnly'=>true),
			array('dt_created', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('sale_id, member_id, product_id, quantity, amount, dt_sale, dt_created', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		
		return array(
		   //'Members'=>array(self::BELONGS_TO, 'Members', 'member_id'),
		   //'Products'=>array(self::BELONGS_TO, 'Products', 'product_id'),
		);
		
		
		
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'sale_id' => 'Sale',
			//'first_name' => 'First Name',
			'product_id' => 'Product',
			'quantity' => 'Quantity',
			'amount' => 'Amount',
			'dt_sale' => 'Dt Sale',
			'dt_created' => 'Dt Created',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
        
		//$criteria->with=array('Members');
		
		$criteria->compare('sale_id',$this->sale_id);
		$criteria->compare('member_id',$this->member_id);
		$criteria->compare('product_id',$this->product_id);
		$criteria->compare('quantity',$this->quantity);
		$criteria->compare('amount',$this->amount);
		$criteria->compare('dt_sale',$this->dt_sale,true);
		$criteria->compare('dt_created',$this->dt_created,true);
		//$criteria->compare('first_name',$this->first_name);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}